#include "UdiskInspection.h"
#include "ui_UdiskInspection.h"
#include "MountWidget.h"
#include "DisplayMainwindow.h"


MyDialog::MyDialog(const QString& path,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::MyDialog)
{
    ui->setupUi(this);
    //标题修改
    this->path = path;
    setWindowTitle("审计移动存储安全平台");
    setWindowIcon(QIcon(":/icons/images/Upan2.png"));

    ui->groupBox_2->setStyleSheet("QGroupBox { background-color: white; "
                                  "border: none; "
                                  "margin-top: 1.5ex; }");
    QPixmap pixmap(":/icons/images/logo.png");
//    ui->label_5->setPixmap(pixmap);
//    ui->label_5->setScaledContents(true);

    ui->label->setText("技术支持单位: \n西安电子科技大学青岛计算技术研究院");
    ui->label->setAlignment(Qt::AlignCenter);

    ui->lineEdit_VerificationCode->setStyleSheet("QLineEdit { border: 1px solid #CCCCCC; background-color: transparent; border-radius: 5px;  }"
                                                 "QLineEdit:focus { border: 1px solid green; }"
                                                 "QLineEdit:hover { border: 1px solid green; }"
                                                 "QLineEdit:pressed { border: 1px solid green; }");

    QString buttonStyle = "QPushButton { background-color: #ADD8E6; border-radius: 8px; }"
                          "QPushButton:pressed { background-color: #6FAAD8; }";
    // 应用样式表
    ui->btnOk->setStyleSheet(buttonStyle);
    ui->btnCancel->setStyleSheet(buttonStyle);
}

MyDialog::~MyDialog()
{
    delete ui;
}
#include <QFile>
#include <QMessageBox>
#include <QThread>



void MyDialog::on_btnOk_clicked()
{

    qDebug()<<"path============"<<path;
    //尝试获取摆渡盘检验码
    QString filePath = path + "/.db/ferrylog";
    //QString filePath = path+"/Verification_Code.txt";
    QFile file(filePath);
    if(file.exists()){
        // Ferryfs fstmp(path);
        // fs = fstmp;
        ferryfs->connectUdiskDB(QString("ferrylog6"));
        QString usb_password = ferryfs->readPasswordFromDB();
        ferryfs->closeDB();
        qDebug()<< "usb_password==" << usb_password;
        QString Input_VC=ui->lineEdit_VerificationCode->text();
        //test
        // QString plain = "6aR1fCpV6D2zKbq8sXgOeNlT7hWt3yJvZ9UoM5dYxGwQ0iLrHpAjE6uBnS2cF5";
        // QString cipher = fs.encryptQString(plain);
        // QString plaintext = fs.decryptQString(cipher);

        if(Input_VC == usb_password || Input_VC == nullptr && usb_password == ferryfs->getDefaultPassword()){
            emit judgmentResult(true); // 发射信号，传递结果
            this->close();
        } else{
            QMessageBox::information(nullptr, "错误", "U盘检验码输入错误！");
        }
    } else {
        QMessageBox::information(nullptr, "错误", "该U盘不是摆渡盘！");
    }
}


void MyDialog::on_btnCancel_clicked()
{
    this->close();
}

